// ajax获取数据
function getData(url) {
	var data;
	$.ajax({
         type: "GET",
         url: url,
         data: {},
         async: false,
         success: function(json){
                     data = json;
                  }
    });
    return data;
}

// 获取流程图坐标信息
function getProcessPosition(processId) {
	var data;
	if (processId == 39034916) {
		data = jsonData;
	} else if (processId == 39034932) {
		data = jsonData2;
	} else if (processId == 39036566) {
		data = jsonData3;
	};
	// data = getData(urlProcessPosition);
	return data;
};

// 获取流程图路径信息
function getProcessPath(processId) {
	var data;
	if (processId == 39034916) {
		data = pathData;
	} else if (processId == 39034932) {
		data = pathData2;
	} else if (processId == 39036566) {
		data = pathData3;
	};
	// data = getData(urlProcessPath);
	return data;
};

// 获取流程图子流程信息
function getSubProcess(processId) {
	var data;
	if (processId == 39034916) {
		data = subProcessData;
	} else if (processId == 39034932) {
		data = subProcess2;
	} else if (processId == 39036566) {
		data = subProcess3;
	};
	// data = getData(urlSubProcess);
	return data;
};

// 获取流程图状态
function getProcessStatus(id, pathData) {
	var pathStatus = {};
	var strokeColor = defaultColor;
	var startTime = "";
	var endTime = "";
	if (pathData.success) {
		var paths = pathData.data.rows;
		$.each(paths,function(i, path) {
			if (id == path.id) {
				if (path.status == passed) {
					strokeColor = passedColor;
					startTime = path.startTime;
					endTime = path.endTime;
				} else if (path.status == current) {
					strokeColor = currentColor;
					startTime = path.startTime;
					endTime = path.endTime;
				} else {
					strokeColor = defaultColor;
					startTime = path.startTime;
					endTime = path.endTime;
				}
				return;
			}
		});
	}
	pathStatus.strokeColor = strokeColor;
	var pathTitle = "";
	if (!isEmpty(startTime)) {
		pathTitle += "开始时间:" + startTime;
		if (!isEmpty(endTime)) {
			pathTitle += "\n结束时间:" +  endTime;
		}
	};
	// pathTitle += "开始时间:";
	// pathTitle += "\n结束时间:";
	pathStatus.pathTitle = pathTitle;
	return pathStatus;
};

// 获取流程图事件
function getProcessEvent(id, subProcess, processId) {
	var processEvent = {};
	if (subProcess.success) {
		var rows = subProcess.data.rows;
		$.each(rows,function(i, row) {
			if (id == row.id) {
				if (row.event == "click") {
					processEvent.eventName = row.event;
					processEvent.processInstanceId = row.action.parameter.processInstanceId;
					processEvent.clickEvent = "drawProcess(" +  row.action.parameter.processInstanceId + ", " + processId + ")";
				};
				return;
			}
		});
	}
	return processEvent;
};

// 添加当前流程信息
function setProcessInfo(processId, parentProcessId) {
	var isPushed = false;
	for (var i = 0; i < processInfo.length; i++) {
		if (processId == processInfo[i].processId) {
			isPushed = true;
			break;
		}
	};
	if (!isPushed) {
		var process = {};
		process.processId = processId;
		process.parentProcessId = parentProcessId;
		processInfo.push(process);
	};
}

// 获取上一级流程id
function getParentProcessId(processId) {
	var parentProcessId;
	for (var i = 0; i < processInfo.length; i++) {
		if (processId == processInfo[i].processId) {
			parentProcessId = processInfo[i].parentProcessId;
			break;
		}
	}
	return parentProcessId;
};

// 返回上一级流程
function processBack(processId) {
	var parentId = getParentProcessId(processId);
	if (event.detail == 2) {
		drawProcess(processId, parentId);
	}
};
